local g = {}

g.Cfg = {};

----
g.isStudio = true;
g.isClient = true;
g.isServer = false;

--- Require librarys -----
local oo = require("SharedLibs.BaseLib");

--- 先导入函数式编程库
oo.ExtentRequire(g, "SharedLibs.FP.Sequence");
oo.ExtentRequire(g, "SharedLibs.FP.Function");
oo.ExtentRequire(g, "SharedLibs.Prototype");

------
local co = require("SharedLibs.CoroLib");

if not g.isStudio then
	oo.enableInterfaceCheck = false;
	oo.enableAsyncCheck = false;
end

g.Debugger = require("SharedLibs.Debugger");
g.PrintStack = g.Debugger.PrintStack;
g.GetRunningCo = co.GetCurrent;

oo.ExtentRequire(g,"SharedLibs.BaseLib");
oo.ExtentRequire(g, "SharedLibs.CoHelper");
oo.ExtentRequire(g, "SharedLibs.CoUtils");

oo.ExtentRequire(g, "SharedLibs.Core");

require("SharedLibs.Ops.CallCC");
require("SharedLibs.Ops.Sequence");
require("SharedLibs.Ops.Parallel");
require("SharedLibs.Ops.WaitTime");
require("SharedLibs.Ops.SWaitTime");
require("SharedLibs.Ops.GuardOp");
require("SharedLibs.Ops.BlockOp");
require("SharedLibs.Ops.Selector");
require("SharedLibs.Ops.WhileOp");

local Array =  require("SharedLibs.Algorithem.Array");
local Map =  require("SharedLibs.Algorithem.Map");
g.newArray = Array.new;
g.Array = Array;
--- 把一个table转换成一个Array对象
g.attachArray = function(arr) return Array.Attach(arr); end
g.newMap = Map.new;

g.callcc = require("SharedLibs.FP.CallCC");
g.run = co.Run;
g.new = co.New;
g.callcc = co.CallCC;
g.newCallcc = co.NewCallCC;
g.coRun = co.CoRun;


g.colize = co.Colize;
g.colass = co.Colass;  --- 将一个class变成colass(融合了coroutine的class)
g.delay = co.Delay; --- delay()会等待一帧, delay(0)则会同步执行（无等待）
g.sDelay = co.SDelay;
g.smartDelay = co.SmartDelay; --- 根据当前是否运行在co里，智能选择如何等待
g.newSelector = co.NewSelector;

--- 
Switch = require("SharedLibs.Ops.Switch");
--- Switch目前是通过封装一个co来实现的, Switch类没有继承AsyncOp, 所以不能newSwitch()
g.switch = function()
	return Switch.new();
end

--g.select = co.Select;

SyncOp = require("SharedLibs.Ops.SyncOp");
--- nop = none operation, 是一个什么都不做的SyncOp
g.nop = function() SyncOp.Default(nil):Wait() end
g.waitFrame = co.WaitFrame;
g.block = co.Block;
g.newBlock = co.NewBlock;
g.newDelay = co.NewDelay;
g.newSDelay = co.NewSDelay;
g.waitCo = co.Wait; --- Note: this wait is wait a coroutine, not do delay!
--- 创建一个roblox内部线程
g.spawn = co.Spawn;

g.sequence = co.Sequence;
g.newSequence = co.NewSequence;
g.newParallel = co.NewParallel;

g.guard = co.Guard;
g.newGuard = co.NewGuard;
g.lambda = co.Lambda;
g.newLambda = co.NewLambda;

g.implemented = oo.implemented;
g.typeof = oo.typeof;

g.Signal = require("SharedLibs.Signal.Signal");
g.SignalWrapper = require("SharedLibs.Signal.SignalWrapper");
g.SignalMerger = require("SharedLibs.Signal.SignalMerger");
g.TupleProperty = require("SharedLibs.Signal.TupleProperty");
g.PropertyMapper = require("SharedLibs.Signal.PropertyMapper");
g.PropertyMapper2 = require("SharedLibs.Signal.PropertyMapper2");

g.Property = require("SharedLibs.Signal.Property");
g.Condition = require("SharedLibs.Signal.Condition");

local SignalExt = "SharedLibs.Signal.SignalExtensions";
g.Signal:extends(SignalExt);
g.SignalWrapper:extends(SignalExt);
g.SignalMerger:extends(SignalExt);

local PropertyExt = "SharedLibs.Signal.PropertyExtensions";
g.Property:extends(SignalExt, PropertyExt);
g.PropertyMapper:extends(SignalExt, PropertyExt);
g.PropertyMapper2:extends(SignalExt, PropertyExt);
g.TupleProperty:extends(SignalExt, PropertyExt);

---
oo.ExtentRequire(g, "SharedLibs.Math.MathUtil");
oo.ExtentRequire(g, "SharedLibs.Utils.TableUtil");
oo.ExtentRequire(g, "SharedLibs.Utils.StringUtil");
oo.ExtentRequire(g, "SharedLibs.Utils.DateUtil");

g.PrintTable = require("SharedLibs.Utils.PrintTable");
g.TimerMgr = oo.ExtentRequire(co, "SharedLibs.TimerMgr");
g.SetTimer = g.TimerMgr.SetTimer;

----

--- 用来执行一个测试方法。func将只在studio里运行
function g.Test(func)
	if not g.isStudio then return end;
	func();
end

return g

